home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Newton Sample Code 1.2 / Data Storage (Soups) / SoupHacking-1 < prev    next >
Encoding:
Text File  |  1993-07-25  |  1.2 KB  |  51 lines  |  [TEXT/R*ch]

  1. // SoupHacking.f
  2. // "Hacking in the Soup"
  3. // Kent Sandvik PIE DTS
  4.  
  5. // This file contains a group of useful functions and
  6. // classes when you need to mess around with soups.
  7.  
  8. // example of how to dump soup contents
  9. func DumpNameSoup()
  10. begin
  11.     local theSoup, c, val;
  12.  
  13. // get soup    
  14.     theSoup := GetStores()[0]:GetSoup("Names");
  15.  
  16. // create a cursor
  17.     local c := Query(theSoup, {type: 'index});
  18.     
  19. // while valid entries, dump the name information out
  20.     repeat
  21.     begin
  22.         val := c:Entry();
  23.         if(val.name.class = 'person) then
  24.         begin
  25.             // modify this as you wish
  26.             print(val.name.last);
  27.             print(val.name.first);
  28.             print(val.city);
  29.             print("\n");
  30.         end;
  31.     end
  32.     until (c:Next() = nil);
  33. end; // big end
  34.  
  35.  
  36. // example of how to creat a soup (delete all entries)
  37. // ex: CreateEmptySoup(GetStores()[0], "Haha", nil);
  38. // or: CreateEmptySoup(GetStores()[0], "Serious", '[{structure: slot, path: theSlotName, type: string}]);
  39.  
  40. func CreateEmptySoup(store, soupName, indexes)
  41. begin
  42.     local s := store:GetSoup(soupName);        // get access to the soup
  43.     
  44.     if s then        // if not NIL
  45.         s:RemoveAllEntries();                    // purge
  46.     else
  47.         s := store:CreateSoup(soupName, indexes);
  48.     
  49.     return s;        // return the soup again
  50. end;
  51.